/**
 * DynamicReports - Free Java reporting library for creating reports dynamically
 *
 * Copyright (C) 2010 - 2013 Ricardo Mariaca
 * http://www.dynamicreports.org
 *
 * This file is part of DynamicReports.
 *
 * DynamicReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DynamicReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with DynamicReports. If not, see <http://www.gnu.org/licenses/>.
 */

package net.sf.dynamicreports.examples.columngrid;

import static net.sf.dynamicreports.report.builder.DynamicReports.*;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.grid.ColumnTitleGroupBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;

/**
 * @author Ricardo Mariaca (r.mariaca@dynamicreports.org)
 */
public class ColumnTitleGroupReport {

	public ColumnTitleGroupReport() {
		build();
	}

	private void build() {
		TextColumnBuilder<Integer> sttColumn = col.reportRowNumberColumn("STT")
				.setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setFixedWidth(30);
		TextColumnBuilder<String> tenDonViColumn = col.column(
				"Tên đơn vị sử dụng", "tenDonViColumn", type.stringType())
				.setFixedWidth(150);
		TextColumnBuilder<String> soHdKtColumn = col.column("Số HĐ KT",
				"soHdKtColumn", type.stringType()).setFixedWidth(50);
		TextColumnBuilder<String> codeColumn = col.column("Mã", "codeColumn",
				type.stringType()).setFixedWidth(50);
		//
		TextColumnBuilder<String> soluong01 = col.column("Số lượng",
				"soluong01", type.stringType()).setFixedWidth(40);
		TextColumnBuilder<String> soTienChuaVATColumn01 = col.column(
				"Số tiền chưa VAT", "soTienChuaVATColumn01", type.stringType())
				.setFixedWidth(80);
		//
		TextColumnBuilder<String> soluong02 = col.column("Số lượng",
				"soluong02", type.stringType()).setFixedWidth(40);
		TextColumnBuilder<String> soTienChuaVATColumn02 = col.column(
				"Số tiền chưa VAT", "soTienChuaVATColumn02", type.stringType())
				.setFixedWidth(80);
		//
		TextColumnBuilder<String> soTienChuaVATColumn03 = col.column(
				"Số tiền chưa VAT", "soTienChuaVATColumn03", type.stringType())
				.setFixedWidth(80);
		//
		TextColumnBuilder<String> soTienChuaVATColumn04 = col.column(
				"Số tiền chưa VAT", "soTienChuaVATColumn04", type.stringType())
				.setFixedWidth(80);
		//
		TextColumnBuilder<String> tongCongChuaVAT = col.column(
				"Tổng Cộng Chưa VAT", "tongCongChuaVAT", type.stringType())
				.setFixedWidth(70);
		// tongCongChuaVAT.setStyle(stl.style().bold().setFontSize(12));
		//
		TextColumnBuilder<String> tongCongDaVAT = col.column(
				"Tổng Cộng ĐÃ VAT", "tongCongDaVAT", type.stringType())
				.setFixedWidth(70);
		//
		ColumnTitleGroupBuilder lapdat = grid.titleGroup("LẮP ĐẶT", soluong01,
				soTienChuaVATColumn01).setTitleFixedHeight(50);
		//
		ColumnTitleGroupBuilder dichchuyenlap = grid.titleGroup(
				"DỊCH CHUYỂN, LẮP //", soluong02, soTienChuaVATColumn02)
				.setTitleFixedHeight(50);
		//
		ColumnTitleGroupBuilder thaythietbi = grid.titleGroup("THAY THIẾT BỊ",
				soTienChuaVATColumn03).setTitleFixedHeight(50);
		//
		ColumnTitleGroupBuilder thukhac = grid.titleGroup("Thu Khác",
				soTienChuaVATColumn04).setTitleFixedHeight(50);

		try {
			report().setTemplate(Templates.reportTemplate)
					.columnGrid(sttColumn, tenDonViColumn, soHdKtColumn,
							codeColumn, lapdat, dichchuyenlap, thaythietbi,
							thukhac, tongCongChuaVAT, tongCongDaVAT)
					.columns(sttColumn, tenDonViColumn, soHdKtColumn,
							codeColumn, soluong01, soTienChuaVATColumn01,
							soluong02, soTienChuaVATColumn02,
							soTienChuaVATColumn03, soTienChuaVATColumn04,
							tongCongChuaVAT, tongCongDaVAT)
					.title(Templates.createTitleComponent(
							"BẢNG KÊ LẮP ĐẶT, DỊCH CHUYỂN, THAY THIẾT BỊ",
							"Tháng 11/2013"))
					.pageFooter(Templates.footerComponent)
					.setDataSource(createDataSource()).show();
		} catch (DRException e) {
			e.printStackTrace();
		}
	}

	private JRDataSource createDataSource() {
		DRDataSource dataSource = new DRDataSource("tenDonViColumn",
				"soHdKtColumn", "codeColumn", "soluong01",
				"soTienChuaVATColumn01", "soluong02", "soTienChuaVATColumn02",
				"soTienChuaVATColumn03", "soTienChuaVATColumn04",
				"tongCongChuaVAT", "tongCongDaVAT");
		dataSource.add("BAN KINH TẾ TW", "Bkê", "01", "3", "1.363.636", "3",
				"590.999", "1.090.909", "0", "3.045.405", "3.350.000");
		dataSource.add("BAN TỔ CHỨC TW", "Bkê", "02", "5", "454.545", "6",
				"954.545", "463.636", "0", "1.872.727", "2.060.000");
		dataSource.add("CỔNG THÔNG TIN ĐIỆN TỬ", "Bkê", "03", "2", "909.091",
				"0", "0", "0", "0", "909.091", "1.000.000");
		dataSource.add("BAN TỔ CHỨC TW", "Bkê", "02", "5", "454.545", "6",
				"954.545", "463.636", "0", "1.872.727", "2.060.000");
		return dataSource;
	}

	public static void main(String[] args) {
		new ColumnTitleGroupReport();
	}
}